home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / programs / lora210e.zip / STRUCT.ZIP / READUSR.C < prev    next >
C/C++ Source or Header  |  1992-04-07  |  2KB  |  78 lines

  1. /*
  2.                           Lora-CBIS Ver. 2.00
  3.  
  4.              Copyright (c) 1989, 1990, 1991 by Marco Maccaferri.
  5.                           All rights reserved.
  6.  
  7.  
  8.                           Source code examples
  9.                        User record read routines
  10.  
  11.  
  12.   You may use this structures at your own risk. The author cannot guarantee
  13.   that this structures are maintained in all future versions of the program.
  14.   You can freely (and you are encouraged on that) distribute this file
  15.   without limitations.
  16.  
  17.   You can contact the autor at one of the following address:
  18.  
  19.   Marco Maccaferri
  20.   BBS: 39-51-6331730 (2:332/402)
  21.   BIX: marco.m
  22.  
  23. */
  24. #include <stdio.h>
  25. #include <io.h>
  26. #include <time.h>
  27. #include <fcntl.h>
  28. #include <string.h>
  29.  
  30. #include "lora.h"
  31. #include "crc32.h"
  32.  
  33. #define MAX_INDEX   500
  34.  
  35. void read_user_record (name)
  36. char *name;
  37. {
  38.    int fd, fflag, m, i, posit;
  39.    long crc;
  40.    struct _usr usr;
  41.    struct _usridx usridx[MAX_INDEX];
  42.  
  43.    crc = 0xFFFFFFFFL;
  44.    for (i=0; i < strlen(name); i++)
  45.       crc = Z_32UpdateCRC (((unsigned short) name[i]), crc);
  46.  
  47.    fd = open ("USERS.BBS", O_RDWR|O_BINARY);
  48.  
  49.    fflag = 0;
  50.    posit = 0;
  51.  
  52.    do {
  53.       i = read(fd,(char *)&usridx,sizeof(struct _usridx) * MAX_INDEX);
  54.       m = i / sizeof (struct _usridx);
  55.  
  56.       for (i=0; i < m; i++)
  57.          if (usridx[i].id == crc)
  58.          {
  59.             posit += i;
  60.             fflag = 1;
  61.             break;
  62.          }
  63.  
  64.       if (!fflag)
  65.          posit += m;
  66.    } while (m == MAX_INDEX && !fflag);
  67.  
  68.    close (fd);
  69.  
  70.    fd = open ("USERS.BBS", O_RDWR|O_BINARY);
  71.  
  72.    lseek (fd, (long)posit * sizeof (struct _usr), SEEK_SET);
  73.    read(fd, (char *)&usr, sizeof(struct _usr));
  74.  
  75.    close(fd);
  76. }
  77.  
  78.